package com.kaiyiweitong.tongxing.fragment.my_coupon;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;

import com.kaiyiweitong.tongxing.R;
import com.kaiyiweitong.tongxing.activity.coupon.CouponDetailActivity;
import com.kaiyiweitong.tongxing.activity.my.MyCouponActivity;
import com.kaiyiweitong.tongxing.adapter.PlatformCouponAdapter;
import com.kaiyiweitong.tongxing.other.SpaceItemDecoration;
import com.kaiyiweitong.tongxing.util.CommonUtil;

/**
 * Created by Administrator on 2017/12/21 0021.
 */

public class StoreCouponFragment extends Fragment {
    private View mView;
    private MyCouponActivity mActivity;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_my_coupon, null);
        mActivity = (MyCouponActivity) getActivity();
        init();
        return mView;
    }

    private void init() {
        mView.findViewById(R.id.no_data).setVisibility(View.INVISIBLE);
        RecyclerView rv=(RecyclerView)mView.findViewById(R.id.rv_my_coupon);
        rv.setLayoutManager(new GridLayoutManager(mActivity, 1, GridLayout.VERTICAL, false));
        PlatformCouponAdapter adapter = new PlatformCouponAdapter(mActivity,mListener);
        rv.addItemDecoration(new SpaceItemDecoration(CommonUtil.dip2px(mActivity,12),1));
        rv.setAdapter(adapter);

    }

    private PlatformCouponAdapter.OnClickListener mListener = new PlatformCouponAdapter.OnClickListener() {
        @Override
        public void onClick(int position) {
            Intent intent = new Intent(mActivity, CouponDetailActivity.class);

            startActivity(intent);
        }
    };
}
